package com.example.hrsystem.data.source;

import androidx.room.Dao;
import androidx.room.Delete;
import androidx.room.Insert;
import androidx.room.Query;
import androidx.room.Update;

import com.example.hrsystem.workflow.model.BusinessTripRequest;

import java.util.Date;
import java.util.List;

/**
 * 出差申请数据库访问接口
 * 提供对出差申请的数据库操作
 */
@Dao
public interface BusinessTripRequestDao {
    /**
     * 获取所有出差申请
     */
    @Query("SELECT * FROM business_trip_requests")
    List<BusinessTripRequest> getAllBusinessTripRequests();

    /**
     * 根据ID获取出差申请
     */
    @Query("SELECT * FROM business_trip_requests WHERE id = :id")
    BusinessTripRequest getBusinessTripRequestById(int id);

    /**
     * 根据流程实例ID获取出差申请
     */
    @Query("SELECT * FROM business_trip_requests WHERE processInstanceId = :processInstanceId")
    BusinessTripRequest getBusinessTripRequestByProcessInstanceId(int processInstanceId);

    /**
     * 根据申请人ID获取出差申请列表
     */
    @Query("SELECT * FROM business_trip_requests WHERE applicantId = :applicantId")
    List<BusinessTripRequest> getBusinessTripRequestsByApplicantId(int applicantId);

    /**
     * 根据状态获取出差申请列表
     */
    @Query("SELECT * FROM business_trip_requests WHERE status = :status")
    List<BusinessTripRequest> getBusinessTripRequestsByStatus(String status);

    /**
     * 根据审批人ID获取待审批的出差申请列表
     */
    @Query("SELECT * FROM business_trip_requests WHERE approverId = :approverId AND status = 'PENDING'")
    List<BusinessTripRequest> getPendingBusinessTripRequestsByApproverId(int approverId);

    /**
     * 查询指定时间段内的出差申请
     */
    @Query("SELECT * FROM business_trip_requests WHERE (startTime <= :endDate AND endTime >= :startDate)")
    List<BusinessTripRequest> getBusinessTripRequestsInDateRange(Date startDate, Date endDate);

    /**
     * 根据目的地查询出差申请
     */
    @Query("SELECT * FROM business_trip_requests WHERE destination LIKE '%' || :destination || '%'")
    List<BusinessTripRequest> getBusinessTripRequestsByDestination(String destination);

    /**
     * 插入出差申请
     */
    @Insert
    void insert(BusinessTripRequest request);

    /**
     * 更新出差申请
     */
    @Update
    void update(BusinessTripRequest request);

    /**
     * 删除出差申请
     */
    @Delete
    void delete(BusinessTripRequest request);
}